// 访问接口路由配置
// author:Xavier

package router

//初始化路由
import (
	"admin_go_api/api/controller"
	"admin_go_api/common/config"
	"admin_go_api/middleware"
	"net/http"

	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

func InitRouter() *gin.Engine {
	router := gin.New()
	// 跌机恢复
	router.Use(gin.Recovery())
	router.Use(middleware.Cors())
	router.StaticFS(config.Config.ImageSetting.UploadDir, http.Dir(config.Config.ImageSetting.UploadDir))
	router.Use(middleware.Logger())
	RegisterRouter(router)
	return router
}

// 路由注册
func RegisterRouter(router *gin.Engine) {
	router.GET("/api/captcha", controller.Captcha)
	router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	router.POST("/api/login", controller.Login)
}
